export default function ({ app, $axios, redirect }, inject) {
  const API = {};

  //服务器地址
  // API.BASEURL = 'http://47.102.152.158:8080/ruoyi-admin'
  API.BASEURL = 'http://124.222.236.194:8080/ruoyi-admin'
  //存入token对应名称
  API.TOKENKEY = 'Admin-Token'

  //以下是登录注册接口

  //生成验证码(图形)和uid
  API.reqCaptchaImage = function (params) {
    return $axios({
      url: '/captchaImage',
      method: 'get',
      data: params,
      headers: {
        'encrypt': 1
      },
    })
  };
  //获取短信验证码
  API.reqPhoneCode = function (params) {
    return $axios({
      url: 'sms/code',
      method: 'post',
      data: params
    })
  },
    //注册
    API.register = function (params) {
      return $axios({
        url: '/register',
        method: 'post',
        data: params,
      })
    };

  //登录（密码登录）
  API.login = function (params) {
    return $axios({
      url: '/login',
      method: 'post',
      data: params,
    })
  }

  //登录（短信登录）
  API.loginSms = function (params) {
    return $axios({
      url: 'sms/login',
      method: 'post',
      data: params,
    })
  }


  //获取用于自己的信息
  API.reqUserInfo = function (params) {
    return $axios({
      url: "/getInfo",
      method: "get",
      data: params,
    });
  };

  //搜索

  // //搜索新闻（按标题）
  // API.reqNewsByTitleAndHits=function(searchKey,pageNum,pageSize){
  //     return $axios({
  //         url: `/system/news/alist?title=${searchKey}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
  //         method: "get",
  //     });
  // }

  // //搜索新闻（按内容）
  // API.reqNewsByContentAndHits = function (searchKey, pageNum, pageSize) {
  //     return $axios({
  //         url: `/system/news/alist?content=${searchKey}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
  //         method: "get",
  //     });
  // }

  // //搜索新闻（按作者）
  // API.reqNewsByAuthorAndHits = function (searchKey, pageNum, pageSize) {
  //     return $axios({
  //         url: `/system/news/alist?authorName=${searchKey}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
  //         method: "get",
  //     });
  // }

  //搜索通识
  // API.reqCoreGeneralByKeyAndHits = function (searchKey, pageNum, pageSize) {
  //   return $axios({
  //     url: `/system/article/alist/common?title=${encodeURI(searchKey)
  //       }&content=${encodeURI(searchKey)}&catalogueName=${encodeURI(searchKey)}&authorName=${encodeURI(searchKey)}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
  //     method: "get",
  //   });
  // }
  //根据作者查
  API.reqCoreGeneralByAuthorAndHits = function (searchKey, pageNum, pageSize) {
      return $axios({
        url: `/system/article/alist/common?authorName=${encodeURI(searchKey)}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
          method: "get",
      });
  }
  //根据题目查
  API.reqCoreGeneralByTitleAndHits = function (searchKey, pageNum, pageSize) {
    return $axios({
      url: `/system/article/alist/common?title=${encodeURI(searchKey)}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
      method: "get",
    });
  }
  //根据内容查
  API.reqCoreGeneralByContentAndHits = function (searchKey, pageNum, pageSize) {
    return $axios({
      url: `/system/article/alist/common?content=${encodeURI(searchKey)}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
      method: "get",
    });
  }
  // //搜索通识（按标题）
  // API.reqCoreGeneralByKeyAndHits = function (searchKey, pageNum, pageSize) {
  //     return $axios({
  //         url: `/system/article/alist/common?title=${encodeURI(searchKey)}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
  //         method: "get",
  //     });
  // }

  //搜索词条
  // API.reqEntryByKeyAndHits = function (searchKey, pageNum, pageSize) {
  //   return $axios({
  //     url: `/system/entry/alist?entryName=${encodeURI(searchKey)
  //       }&entryContent=${encodeURI(searchKey)}&cataName=${encodeURI(searchKey)}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
  //     method: "get",
  //   });
  // }
  API.reqEntryByKeyAndHits = function (searchKey, pageNum, pageSize) {
    return $axios({
      url: `/system/entry/alist?entryName=${encodeURI(searchKey)}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
      method: "get",
    });
  }
  // API.reqEntryByKeyAndHits = function (searchKey, pageNum, pageSize) {
  //   return $axios({
  //     url: `/system/entry/alist?cataName=${encodeURI(searchKey)}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
  //     method: "get",
  //   });
  // }


  //下面是用户文章页面的

  //获取点赞状态
  API.reqIsLike = function (userId, artId) {
    return $axios({
      url: `system/likes/status?userId=${userId}&artId=${artId}&orderBy=hits`,
      method: 'get',
    })
  }

  //获取收藏状态
  API.reqIsCollect = function (userId, artId) {
    return $axios({
      url: `system/favorites/status?userId=${userId}&artId=${artId}`,
      method: 'get',
    })
  }

  //点赞
  API.reqLikes = function (params) {
    return $axios({
      url: 'system/likes',
      method: 'post',
      data: params,
    })
  }

  //取消点赞
  API.reqCancelLikes = function (userId, artId) {
    return $axios({
      url: `system/likes?userId=${userId}&artId=${artId}`,
      method: 'delete',
    })
  }

  //收藏
  API.reqCollect = function (params) {
    return $axios({
      url: 'system/favorites',
      method: 'post',
      data: params,
    })
  }

  //取消收藏
  API.reqCancelCollect = function (userId, artId) {
    return $axios({
      url: `system/favorites?userId=${userId}&artId=${artId}`,
      method: 'delete',
    })
  }

  //根据文章id获取文章评论
  API.reqArticleComments = function (params) {
    return $axios({
      url: `system/article/comments/${params}`,
      method: 'get',
    })
  }
  //根据评论id获取评论
  API.getComments = function (params) {
    return $axios({
      url: `system/comments/responsied/a/${params}`,
      method: 'get',
    })
  },

    //新增评论
    API.addComments = function (params) {
      return $axios({
        url: 'system/comments',
        method: 'post',
        data: params,
      })
    }
  //删除评论
  API.deleteComment = function (commentId, userId) {
    return $axios({
      url: `system/comments?commentId=${commentId}&userId=${userId}`,
      method: 'delete',
    })
  }
  //根据文章id获取文章
  API.reqArticle = function (params) {
    return $axios({
      url: `system/article/a/${params}`,
      method: 'get',
    })
  }
  //根据词条id获取词条
  API.reqEntry = function (entryId) {
    return $axios({
      url: `system/entry/a/${entryId}`,
      method: 'get',
    })
  }


  //以下是首页

  //获取新闻焦点
  API.reqNews = function () {
    return $axios({
      url: "/system/news/alist?pageNum=1&pageSize=10",
      method: "get",
    });
  };

  //   API.reqNews = function () {
  //     return $axios.get('/system/news/alist?pageNum=1&pageSize=10',{useCache:true})
  // };

  //获取热点新闻详细信息
  API.reqNewsDetail = function (newsId) {
    return $axios({
      url: `/system/news/a/${newsId}`,
      method: "get",
    });
  }

  //获取用户修改信息列表
  API.reqUserWriteList = function (artType) {
    return $axios({
      url: `system/article/alist/common?artType=${artType}&orderBy=publishTime&pageNum=1&pageSize=10`,
      method: 'get',
    })
  }

  //分页获取核心通识
  API.reqCoreGeneralByPage = function (catalogue, pageNum = 1, pageSize = 10) {
    return $axios({
      url: `system/article/alist/${catalogue}?pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
      method: 'get',
    })
  }
  //   API.reqCoreGeneralByPage = function (catalogue,pageNum=1, pageSize=10) {
  //     return $axios.get(`system/article/alist/${catalogue}?pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,{useCache:true})
  // }
  // //分类获取核心通识列表（总体）
  // API.reqGeneralAllByCatalogue=function(catalogue){
  //     return $axios({
  //         url: `system/article/alist/${catalogue}?pageNum=1&pageSize=10`,
  //         method: 'get',
  //     })
  // }
  //分类获取核心通识列表（总体）
  API.reqGeneralAllByCatalogue = function (catalogue, pageNum = 1, pageSize = 10) {
    return $axios({
      url: `system/article/alllist/?catalogueId=${catalogue}&pageNum=${pageNum}&pageSize=${pageSize}&orderBy=hits`,
      method: 'get',
    })
  }

  //查询健康通识列表（点击量降序）
  API.reqCoreGeneralByHits = function () {
    return $axios({
      url: `system/article/alist/hits?pageNum=1&pageSize=10`,
      method: 'get',
    })
  }


  //查询健康通识列表（点赞量降序）
  API.reqCoreGeneralByLikes = function () {
    return $axios({
      url: `system/article/alist/likes?pageNum=1&pageSize=10`,
      method: "get",
    });
  };

  //创作中心
  //保存草稿
  API.reqDrafts = function (params) {
    return $axios({
      url: `system/drafts`,
      method: "post",
      data: params,
    });
  };
  // 删除草稿
  API.reqCancelDrafts = function (draftId) {
    return $axios({
      url: `system/drafts/${draftId}`,
      method: 'delete',
    })
  }
  // 修改草稿
  API.reqUpdateDrafts = function (params) {
    return $axios({
      url: `system/drafts`,
      method: 'put',
      data: params
    })
  }
  // 根据草稿id获取草稿内容
  API.reqGetDrafts = function (draftId) {
    return $axios({
      url: `system/drafts/${draftId}`,
      method: 'get'
    })
  }

  //上传文章
  API.reqAddArticle = function (params) {
    return $axios({
      url: `system/article/upload`,
      method: "post",
      data: params,
    });
  };
  //修改文章
  API.reqUpdateArticle = function (params) {
    return $axios({
      url: `system/article`,
      // method: "put",
      method: "post",
      data: params,
    });
  };
  //查询文章目录
  API.reqArtsList = function () {
    return $axios({
      url: `system/artcatalogue/list`,
      method: "get",
    });
  };
  //上传文件
  API.reqArtcatalogueList = function (data) {
    return $axios({
      url: `common/upload`,
      method: "post",
      data,
    });
  };
  //医生认证
  API.reqDoctorCtertify = function (data) {
    return $axios({
      url: `system/doctor`,
      method: "post",
      data,
    });
  };


  //根据id获取通识列表详细信息
  API.reqCoreGeneralByArtId = function (params) {
    return $axios({
      url: `system/article/a/${params}`,
      method: 'get',
    })
  }

  //查询健康手册列表
  API.searchManualList = function () {
    return $axios({
      url: 'system/manual/alist',
      method: 'get',
    })
  }

  //根据文件名下载
  API.downloadByFile = function (fileName) {
    return $axios({
      url: `system/manual/alist?manualIntro=${encodeURI(fileName)}`,
      method: 'get',
    })
  }

  //下载
  API.download = function (fileName) {
    return $axios({
      url: `common/download/resource?resource=${encodeURI(fileName)}`,
      method: 'get',
    })
  }

  //以下是医生界面

  //获取医生（营养师，健康管理师）等列表
  API.reqAllDoctor = function () {
    return $axios({
      url: 'system/doctor/list?pageNum=1&pageSize=10',
      method: 'get',
    })
  }

  //获取类别获取医生/健康管理师/营养师列表(0:医生,1:健康管理师,2:营养师)
  API.reqDoctor = function (params) {
    return $axios({
      url: `system/doctor/list?type=${params}&pageNum=1&pageSize=10`,
      method: 'get',
    })
  }

  //获取类别获取医生/健康管理师/营养师列表(0:医生,1:健康管理师,2:营养师)——分页
  API.reqDoctorByPage = function (type, pageNum = 1, pageSize = 9) {
    return $axios({
      url: `system/doctor/list?type=${type}&pageNum=${pageNum}&pageSize=${pageSize}`,
      method: 'get',
    })
  }

  //根据医生id获取医生相关信息
  API.reqDoctorInfo = function (doctorId) {
    return $axios({
      url: `system/doctor/${doctorId}`,
      method: 'get',
    })
  }


  //页脚

  //获取通知公告列表
  API.reqNoticeList = function () {
    return $axios({
      url: `system/notice/list`,
      method: 'get',
    })
  }

  //根据公告编号获取详细信息
  API.reqNoticeById = function (noticeId) {
    return $axios({
      url: `system/notice/${noticeId}`,
      method: 'get',
    })
  }
  //意见反馈
  API.reqFeedbacks = function (data) {
    return $axios({
      url: `system/feedbacks`,
      method: "post",
      data,
    });
  }

  //5.12 私信
  API.reqPrivateMsg = function (sendId, receiveId) {
    return $axios({
      url: `system/healthPrivateMessage/alist?receiveId=${receiveId}&sendId=${sendId}`,
      method: "get",
      // data,
    });
  }
  //查询对方用户详细信息
  API.reqSendIdInfo = function (userId) {
    return $axios({
      url: `system/user/a/${userId}`,
      method: "get",
      // data,
    });
  }
  //查询私信列表
  API.reqMessageList = function (userId) {
    return $axios({
      url: `system/healthPrivateMessage/list/${userId}`,
      method: "get",
      // data,
    });
  }
  //根据用户id查询最近通信信息
  API.reqSendIdnewList = function (userId) {
    return $axios({
      url: `system/healthPrivateMessage/newlist/${userId}`,
      method: "get",
      // data,
    });
  }
  // 用户信息

  // 根据用户编号获取用户详细信息
  API.reqUserDetail = function (userId) {
    return $axios({
      url: `system/user/a/${userId}`,
      method: 'get',
    })
  }
  // 根据用户id查询用户的发布文章的浏览量
  API.reqPubCount = function (userId) {
    return $axios({
      url: `system/user/pubcount/${userId}`,
      method: 'get'
    })
  }
  // 获取当前用户关注列表
  API.reqSubscribeList = function (userId) {
    return $axios({
      url: `system/subscribetable/list/${userId}`,
      method: 'get'
    })
  }
  // 获取当前用户粉丝列表
  API.reqFansList = function (userId) {
    return $axios({
      url: `system/subscribetable/listFans/${userId}`,
      method: 'get'
    })
  }
  // 个人信息修改--上传头像
  API.reqUploadAvatar = function (formData) {
    return $axios({
      url: `system/user/profile/avatar`,
      method: 'post',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      data: formData,
    })
  }
  // 个人信息修改--修改个人信息
  API.reqUpdateProfile = function (params) {
    return $axios({
      url: `system/user/profile`,
      method: 'put',
      data: params
    })
  }
  // 重置密码
  API.reqUpdatePwd = function (oldPwd, newPwd) {
    return $axios({
      url: `system/user/profile/updatePwd?oldPassword=${oldPwd}&newPassword=${newPwd}`,
      method: 'put',
    })
  }
  // 获取邮件验证码
  API.reqEmailCode = function (emailNum) {
    return $axios({
      url: `email/code?email=${emailNum}`,
      method: 'get'
    })
  }
  // 获取当前用户关注列表
  API.reqFocusList = function (userId) {
    return $axios({
      url: `system/subscribetable/list/${userId}`,
      method: 'get'
    })
  }
  // 获取当前用户粉丝列表
  API.reqFansList = function (userId) {
    return $axios({
      url: `system/subscribetable/listFans/${userId}`,
      method: 'get'
    })
  }
  // 系统消息列表详情
  API.reqSystemNotice = function (listId) {
    return $axios({
      url: `system/notice/${listId}`,
      method: 'get'
    })
  }
  // 留言列表
  API.reqMessageList = function (userId) {
    return $axios({
      url: `system/healthPrivateMessage/list/${userId}`,
      method: 'get'
    })
  }
  // 使用手机更改邮箱
  API.reqAlterEmail = function (params) {
    return $axios({
      url: `authorize/alterEmail`,
      method: 'post',
      data: params
    })
  }
  // 使用有限更改手机
  API.reqAlterPhone = function (params) {
    return $axios({
      url: `authorize/alterPhoneNumber`,
      method: 'post',
      data: params
    })
  }
  // 根据用户id查询用户的发布文章列表
  API.reqPublishList = function (userId) {
    return $axios({
      url: `system/user/publish/${userId}`,
      method: 'get'
    })
  }
  // 草稿箱列表
  API.reqDraftList = function (userId) {
    return $axios({
      url: `system/user/drafts/${userId}`,
      method: 'get'
    })
  }
  // 删除草稿
  API.reqDelDraft = function (draftId) {
    return $axios({
      url: `system/user/drafts/${draftId}`,
      method: 'delete'
    })
  }
  // 喜欢列表
  API.reqLikeList = function (userId) {
    return $axios({
      url: `system/user/like/${userId}`,
      method: 'get'
    })
  }
  // 收藏列表
  API.reqCollectList = function (userId) {
    return $axios({
      url: `system/user/collect/${userId}`,
      method: 'get'
    })
  }
  // 获取关注状态
  API.reqCheckStatus = function (parmas) {
    return $axios({
      url: `system/subscribetable/check`,
      method: 'post',
      data: parmas
    })
  }
    // 取消关注
    API.reqDeleteFocus = function(subscribedId){
      return $axios({
        url:`system/subscribetable/${subscribedId}`,
        method:'delete'
      })
    },
    // 关注用户
    API.reqAddFocus = function(subscribedId){
      return $axios({
        url:`system/subscribetable/${subscribedId}`,
        method:'post'
      })
    },
    //获取用户发布文章的点赞量
    API.reqLikeCount = function (userId) {
      return $axios({
        url: `system/user/likecount/${userId}`,
        method: 'get'
      })
    }
  //获取用户发布文章的浏览量
  API.reqPubCount = function (userId) {
    return $axios({
      url: `system/user/pubcount/${userId}`,
      method: 'get'
    })
  }
  //获取用户粉丝数
  API.reqFansCount = function (userId) {
    return $axios({
      url: `system/subscribetable/listFans/${userId}`,
      method: 'get'
    })
  }
  app.api = API;
  inject('api', API);
}
